package org.microservice.common.base;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.microservice.common.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: 齐丹枫
 * Date: 2018/8/9
 * Time: 14:10
 * To change this template use File | Settings | File Templates.
 * Description:
 */
public class BaseControllerImpl<M extends BaseMapper<T>,T> implements BaseController<T>{

    @Autowired
    private M baserMapper;

    @Override
    @PostMapping("/getListPage")
    public R getListPage(@RequestBody Map<String, Object> params) {

        return R.ok();
    }

    @Override
    @PostMapping("/update")
    public R update(@RequestBody T t) {
        baserMapper.updateById(t);
        return R.ok();
    }

    @Override
    @PostMapping("/save")
    public R save(@RequestBody T t) {
        baserMapper.insert(t);
        return R.ok();
    }

    @Override
    @GetMapping("/getById")
    public R getById(@RequestParam("id")  Serializable id) {
        T t = baserMapper.selectById(id);

        return R.ok().put("data",t);
    }


    @Override
    @GetMapping("/deleteById")
    public R deleteById(@RequestParam("id") Serializable id) {
        //baserMapper.deleteById(id);
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        baserMapper.deleteByMap(map);
        return R.ok();
    }

}
